package com.drinks.yiniang.adapter.user.points;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.entity.user.points.PointsExchangeJson;
import com.hansen.library.utils.ScreenSizeUtils;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 积分兑换列表adapter
 * @author han
 * @date 2019/8/30
 */
public class PointsExchangeAdapter extends BaseQuickRCVAdapter<PointsExchangeJson.PointsExchangeList, BaseViewHolder> {

    private SpannableStringBuilder mBuilder;

    private int sp18;

    public PointsExchangeAdapter(Context mContext, @Nullable List<PointsExchangeJson.PointsExchangeList> data) {
        super(R.layout.item_points_exchange, data);

        mBuilder = new SpannableStringBuilder();

        sp18 = ScreenSizeUtils.sp2Px(mContext, 18);
    }

    @Override
    protected void convert(BaseViewHolder helper, PointsExchangeJson.PointsExchangeList item) {
        //优惠券金额
        mBuilder.clearSpans();
        mBuilder.clear();
        mBuilder.append("¥");
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getAmount()));
        mBuilder.setSpan(new AbsoluteSizeSpan(sp18), 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        helper.setText(R.id.tv_pot_exc_coupon_value, mBuilder);
        //兑换所需积分
        helper.setText(R.id.tv_pot_exc_value, String.format(mContext.getString(R.string.text_use_point_exchange_format), StringUtils.getNullEmptyConvert__(item.getCost_points())));
        //满可用
        helper.setText(R.id.tv_pot_exc_coupon_require, String.format(mContext.getString(R.string.text_use_limit_money_format), StringUtils.getNullEmptyConvert__(item.getLimit_amount())));
        //期限
        mBuilder.clearSpans();
        mBuilder.clear();
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getStart_time()));
        mBuilder.append("—");
        mBuilder.append(StringUtils.getNullEmptyConvert__(item.getEnd_time()));
        helper.setText(R.id.tv_pot_exc_coupon_use_time, mBuilder);
        //使用平台
        helper.setText(R.id.tv_pot_exc_coupon_use_place, StringUtils.isPositiveIntNumber(item.getStores_id())
                ? String.format(mContext.getString(R.string.text_only_one_store_use_format), StringUtils.getNullEmptyConvert__(item.getStores_name()))
                : mContext.getString(R.string.text_coupon_use_by_all));
    }
}
